<?php



namespace Admin\Controller;



/**
 * 身份审核控制器
 */

class AuthController extends AdminController

{

	public function index($passed = ''){

		$passed = empty($passed) ? $_GET['passed'] = 0 : $passed;

		$lists = D('Auth') -> authList($passed);

		// dump($lists);die;

		$this -> assign('lists', $lists);

		$this -> display();

	}



	/**
	 * 修改课程条目状态：通过，不通过，删除
	 * @return [type] [description]
	 */

	public function edit(){

		if (IS_AJAX) {

			$uid = I('post.uid');
			$val = I('post.val');
			$flag = I('post.flag');
			if($flag == "status"){
				$where['uid'] = $uid;
				if(D('Auth') ->where($where) ->delete()){
					$this -> ajaxReturn('删除成功');
				}else{
					$this -> ajaxReturn('删除失败');
				}
			}

			//如果修改了pass状态

			if ($flag == 'passed') {
				$model = M();
				$model -> startTrans();
				if($val == 1){
					$msg['sid']	    = 0;
					$msg['rid'] 	= $uid;
					$msg['content'] = '您提交身份认证已通过，感谢您的使用。';
					$msg['type']    = 4;

				} elseif ($val == 2) {

					$msg['sid']	    = 0;
					$msg['rid'] 	= $uid;
					$msg['content'] = '您提交身份认证未通过，请您修改后提交，感谢您的使用。';
					$msg['type']    = 4;

				}

				//修改auth表并发送信息
				$res = D('Message') -> add($msg) && D('Auth') -> edit($uid, $val, $flag);
				if ($res) {
					$model -> commit();
				} else {
					$model -> rollback();
				}
			} else {
				$res = D('Auth') -> edit($uid, $val, $flag);
			}
			if ($res) {
				/*记录操作时间 start yjmp*/
				D('Auth') -> edit($uid, time(), 'update_time');
				/*记录操作时间 end*/
				$this -> ajaxReturn('操作成功');

			} else {
				$this -> ajaxReturn('出错了');
			}
		}
	}
	
	/**
	 * 批量审核
	 * @return [type] [description]
	 */

	public function ajaxedit(){
		if (IS_AJAX) {
            $ids = I('post.ids');
			//$uid = I('post.uid');
			$val = I('post.val');
			$flag = I('post.flag');
			if(empty($ids)){
				$this -> ajaxReturn('操作失败');
				return;
			}
			foreach($ids as $value){
				$uid = 0;
				$uid = $value;
				//如果修改了pass状态
				if ($flag == 'passed') {
					$model = M();
					$model -> startTrans();
					if($val == 1){
						$msg['sid']	    = 0;
						$msg['rid'] 	= $uid;
						$msg['content'] = '您提交身份认证已通过，感谢您的使用。';
						$msg['type']    = 4;

					} elseif ($val == 2) {
						$msg['sid']	    = 0;
						$msg['rid'] 	= $uid;
						$msg['content'] = '您提交身份认证未通过，请您修改后提交，感谢您的使用。';
						$msg['type']    = 4;
					}

					//修改auth表并发送信息
					$res = D('Message') -> add($msg) && D('Auth') -> edit($uid, $val, $flag);
					if ($res) {
						/*记录操作时间 start yjmp*/
						D('Auth') -> edit($uid, time(), 'update_time');
						/*记录操作时间 end*/
						$model -> commit();
					} else {

						$model -> rollback();

					}

				} else {

					$res = D('Auth') -> edit($uid, $val, $flag);

				}

			}
			

			$this -> ajaxReturn('操作成功');

		}

	}
	
	
	
	
	
	
	
	
	
	
	

}

